home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qarray.h.z / qarray.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  6.5 KB  |  161 lines

  1. /****************************************************************************
  2. ** $Id: qarray.h,v 2.3 1998/07/03 00:09:42 hanord Exp $
  3. **
  4. ** Definition of QArray template/macro class
  5. **
  6. ** Created : 930906
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QARRAY_H
  25. #define QARRAY_H
  26.  
  27. #ifndef QT_H
  28. #include "qgarray.h"
  29. #endif // QT_H
  30.  
  31.  
  32. #if defined(USE_MACROCLASS)
  33.  
  34. #include "qgeneric.h"
  35.  
  36. #if !defined(name2)
  37. #define name2(a,b)    name2_xx(a,b)
  38. #define name2_xx(a,b) a##b
  39. #endif
  40.  
  41. #if defined(DEFAULT_MACROCLASS)
  42. #define QArraydeclare QArrayMdeclare
  43. #define QArray QArrayM
  44. #endif
  45. #define QArrayM(type) name2(QArrayM_,type)
  46.  
  47. #define QArrayMdeclare(type)                              \
  48. class QArrayM(type) : public QGArray                          \
  49. {                                          \
  50. protected:                                      \
  51.     QArrayM(type)( int, int ) : QGArray( 0, 0 ) {}                  \
  52. public:                                          \
  53.     QArrayM(type)()        {}                          \
  54.     QArrayM(type)( int size ) : QGArray(size*sizeof(type)) {}              \
  55.     QArrayM(type)( const QArrayM(type) &a ) : QGArray(a) {}              \
  56.    ~QArrayM(type)()        {}                          \
  57.     QArrayM(type)& operator=(const QArrayM(type) &a)                  \
  58.                 { return (QArrayM(type)&)QGArray::assign(a); }\
  59.     type *data()    const    { return (type *)QGArray::data(); }          \
  60.     uint  nrefs()   const    { return QGArray::nrefs(); }              \
  61.     uint  size()    const    { return QGArray::size()/sizeof(type); }      \
  62.     bool  isEmpty() const    { return QGArray::size() == 0; }          \
  63.     bool  isNull()  const    { return QGArray::data() == 0; }          \
  64.     bool  resize( uint size )    { return QGArray::resize(size*sizeof(type)); }\
  65.     bool  truncate( uint pos )    { return QGArray::resize(pos*sizeof(type)); } \
  66.     bool  fill( const type &d, int size=-1 )                      \
  67.     { return QGArray::fill((char*)&d,size,sizeof(type) ); }              \
  68.     void  detach()        { QGArray::detach(); }                  \
  69.     QArrayM(type)   copy() const                          \
  70.     { QArrayM(type) tmp; return tmp.duplicate(*this); }              \
  71.     QArrayM(type)& assign( const QArrayM(type)& a )                  \
  72.     { return (QArrayM(type)&)QGArray::assign(a); }                  \
  73.     QArrayM(type)& assign( const type *a, uint n )                  \
  74.     { return (QArrayM(type)&)QGArray::assign((char*)a,n*sizeof(type));}   \
  75.     QArrayM(type)& duplicate( const QArrayM(type)& a )                  \
  76.     { return (QArrayM(type)&)QGArray::duplicate(a); }              \
  77.     QArrayM(type)& duplicate( const type *a, uint n )                  \
  78.     { return (QArrayM(type)&)QGArray::duplicate((char*)a,n*sizeof(type));}\
  79.     QArrayM(type)& setRawData( const type *a, uint n )                  \
  80.     { return (QArrayM(type)&)QGArray::setRawData((char*)a,              \
  81.                              n*sizeof(type)); }          \
  82.     void resetRawData( const type *a, uint n )                      \
  83.     { QGArray::resetRawData((char*)a,n*sizeof(type)); }              \
  84.     int     find( const type &d, uint i=0 ) const                      \
  85.     { return QGArray::find((char*)&d,i,sizeof(type)); }              \
  86.     int     contains( const type &d ) const                      \
  87.     { return QGArray::contains((char*)&d,sizeof(type)); }              \
  88.     type& operator[]( int i ) const                          \
  89.     { return (type &)(*(type *)QGArray::at(i*sizeof(type))); }          \
  90.     type& at( uint i ) const                              \
  91.     { return (type &)(*(type *)QGArray::at(i*sizeof(type))); }          \
  92.      operator const type*() const { return (const type *)QGArray::data();}\
  93.     bool operator==( const QArrayM(type) &a ) const { return isEqual(a); }    \
  94.     bool operator!=( const QArrayM(type) &a ) const { return !isEqual(a); }   \
  95. }
  96.  
  97. #endif // USE_MACROCLASS
  98.  
  99.  
  100. #if defined(USE_TEMPLATECLASS)
  101.  
  102. #if defined(DEFAULT_TEMPLATECLASS)
  103. #undef    QArray
  104. #define QArray QArrayT
  105. #endif
  106.  
  107. template<class type> class QArrayT : public QGArray
  108. {
  109. protected:
  110.     QArrayT( int, int ) : QGArray( 0, 0 ) {}
  111. public:
  112.     QArrayT()            {}
  113.     QArrayT( int size ) : QGArray(size*sizeof(type)) {}
  114.     QArrayT( const QArrayT<type> &a ) : QGArray(a) {}
  115.    ~QArrayT()            {}
  116.     QArrayT<type> &operator=(const QArrayT<type> &a)
  117.                 { return (QArrayT<type>&)QGArray::assign(a); }
  118.     type *data()    const    { return (type *)QGArray::data(); }
  119.     uint  nrefs()   const    { return QGArray::nrefs(); }
  120.     uint  size()    const    { return QGArray::size()/sizeof(type); }
  121.     bool  isEmpty() const    { return QGArray::size() == 0; }
  122.     bool  isNull()  const    { return QGArray::data() == 0; }
  123.     bool  resize( uint size )    { return QGArray::resize(size*sizeof(type)); }
  124.     bool  truncate( uint pos )    { return QGArray::resize(pos*sizeof(type)); }
  125.     bool  fill( const type &d, int size=-1 )
  126.     { return QGArray::fill((char*)&d,size,sizeof(type) ); }
  127.     void  detach()        { QGArray::detach(); }
  128.     QArrayT<type>   copy() const
  129.     { QArrayT<type> tmp; return tmp.duplicate(*this); }
  130.     QArrayT<type>& assign( const QArrayT<type>& a )
  131.     { return (QArrayT<type>&)QGArray::assign(a); }
  132.     QArrayT<type>& assign( const type *a, uint n )
  133.     { return (QArrayT<type>&)QGArray::assign((char*)a,n*sizeof(type)); }
  134.     QArrayT<type>& duplicate( const QArrayT<type>& a )
  135.     { return (QArrayT<type>&)QGArray::duplicate(a); }
  136.     QArrayT<type>& duplicate( const type *a, uint n )
  137.     { return (QArrayT<type>&)QGArray::duplicate((char*)a,n*sizeof(type)); }
  138.     QArrayT<type>& setRawData( const type *a, uint n )
  139.     { return (QArrayT<type>&)QGArray::setRawData((char*)a,
  140.                              n*sizeof(type)); }
  141.     void resetRawData( const type *a, uint n )
  142.     { QGArray::resetRawData((char*)a,n*sizeof(type)); }
  143.     int     find( const type &d, uint i=0 ) const
  144.     { return QGArray::find((char*)&d,i,sizeof(type)); }
  145.     int     contains( const type &d ) const
  146.     { return QGArray::contains((char*)&d,sizeof(type)); }
  147.     type& operator[]( int i ) const
  148.     { return (type &)(*(type *)QGArray::at(i*sizeof(type))); }
  149.     type& at( uint i ) const
  150.     { return (type &)(*(type *)QGArray::at(i*sizeof(type))); }
  151.      operator const type*() const { return (const type *)QGArray::data(); }
  152.     bool operator==( const QArrayT<type> &a ) const { return isEqual(a); }
  153.     bool operator!=( const QArrayT<type> &a ) const { return !isEqual(a); }
  154. };
  155.  
  156.  
  157. #endif // USE_TEMPLATECLASS
  158.  
  159.  
  160. #endif // QARRAY_H
  161.